package com.xyq.practice;

import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetPractice {
    public static void main(String[] args) {
        TreeSet<person> ts = new TreeSet<>(new Comparator<person>() {
            @Override
            public int compare(person o1, person o2) {
                //o2总成绩-o1总成绩
                return(int)(o2.getChinese() +  o2.getMath() + o2.getEnglish() - (o1.getChinese() + o1.getMath() + o1.getEnglish()));
            }
        });
        Scanner  scanner = new Scanner(System.in);

        for (int i = 0; i < 3; i++){
            System.out.println("请输入第"+(i+1)+"个学生的信息");
            System.out.println("请输入姓名");
            String name = scanner.next();
            System.out.println("请输入语文成绩");
            double chinese = scanner.nextDouble();
            System.out.println("请输入数学成绩");
            double math = scanner.nextDouble();
            System.out.println("请输入英语成绩");
            double english = scanner.nextDouble();
            //创建person对象
            person p = new person(name, chinese, math, english);
            //把person对象添加到TreeSet集合中
            ts.add(p);
        }
        //遍历TreeSet集合增强for
        for (person p : ts){
            System.out.println(p);
        }
    }
}
